// JavaScript Document
$(function(){
	$("a.add-tag").click(function(){
		if($(this).hasClass("open-taginfo")){
			$(this).addClass("close-taginfo").removeClass("open-taginfo");
			$(".close-tag").css("display","block");
		}else{
			$(this).addClass("open-taginfo").removeClass("close-taginfo");
			$(".close-tag").css("display","none");
		}
		$(".tag-container").stop().animate({"opacity": "toggle", "height": "toggle"}, "fast");
	});	//tag标签增添
	
	$(".Hot-info>ul>li").mouseover(function(){
		$(this).addClass("AtcNow").siblings(".AtcList").removeClass("AtcNow");
	});
	
	var Li = $(".slideList").find("li");
	var _liL = Li.length;
	var _liW = Li.outerWidth(true);
	$(".slideList").width(_liW*_liL);	//左侧轮播ul的宽度
	var k = 0;
	$(".RarrowBtn").click(function(){
		if(k <= -Math.ceil(_liL/3)+1){
			k=0;
		}else{
			k-=1;
		}
		SlideLeft(k)
	});
	$(".LarrowBtn").click(function(){
		if(k >= 0){
			k= -Math.ceil(_liL/3)+1;
		}else{
			k+=1;
		}
		SlideLeft(k)
	});
	function SlideLeft(k){
		$(".slideList").stop().animate({"margin-left": 3*k*_liW+"px"}, 500)
	}//左侧图片列表轮播
	
	$(".login").click(function(e){
		StopPro(e);
		Show($(".AlertBg"));
		Show($(".AlertDenglu"));
	})//登陆
	$(".register").click(function(e){
		StopPro(e);
		Show($(".AlertBg"));
		Show($(".AlertZhuce"));
	});//注册
	$(".RegisterBtn").click(function(e){
		StopPro(e);
		Hide($(this).parents(".AlertContainer"));
		Show($(".AlertBg"));
		Show($(".AlertZhuCG"));
	})//注册成功
	$(document).click(function(e){
		Hide($(".AlertBg"));
		Hide($(".AlertContainer"));
	})
	$(".AlertContainer").bind("click",function(e){StopPro(e);})
	
	function StopPro(e){	//阻止冒泡
		var e = e || window.event;
		if(e.stopPropagation)
			e.stopPropagation();
		else
			e.cancelBubble = true;
	}
	function Show(obj){
		obj.css("display","block")
	}
	function Hide(obj){
		obj.css("display","none")
	}//end AlertBg
	
	$(window).load(function(){
		/*Start img 宽度比例*/
		var img = $(".DakaUserImg").find("img");
		img.each(function(i, o) {
			var _w = this.width;
			var _h = this.height;
			var W = 0, H = 0;
			if(_w>=_h&&_h>50){
				H = 50;
				W = H*_w/_h;
				this.style.marginLeft = (H-W)/2 + "px";
			}
			else if(_h>_w&&_w>50){
				W = 50;
				H = W*_h/_w;
				this.style.marginTop = (W-H)/2 + "px";
			}
			else if(_h<50||_W<50){
				H = _h;
				W = _w;
				this.style.marginTop = (50-H)/2 + "px";
				this.style.marginLeft = (50-W)/2 + "px";
			}
			this.style.width = W + "px";
			this.style.height = H + "px";
		});	//圆角图片
		
		$(".cmtMainImg").ImgRatio();
		$(".slideLi a").ImgRatio();
	});
	
	var TagInfo = $(".tag-parent");
	var TagTop = TagInfo.offset().top;
	var ScrollTop = $(window).scrollTop();
	$(window).scroll(function(){
		ScrollTop = $(this).scrollTop();
		if(ScrollTop>=TagTop+100){
			TagInfo.addClass("TagFixed");
			TagInfo.animate({"top":0},500);
			TagInfo.find(".iconmore").hide();
		}else{
			TagInfo.removeClass("TagFixed");
			TagInfo.css("top","-50px");
			TagInfo.find(".iconmore").show();
		}
		console.log(TagTop);
	});
})